package stdlib.io

import java.io.File

const val filename = "test.txt"
fun main() {
    val file = File(filename)
    if (!file.exists()) {
        println("$filename 不存在")
        val created = file.createNewFile()
        if (created) {
            println("$filename 创建成功")
        }
    } else {
        println("$filename 存在")
    }

    file.writeText("hello world")
    val text = file.readText()
    println("read $text")

    println("file.absolutePath ${file.absolutePath}")
    println("file.canonicalPath ${file.canonicalPath}")
    println("file.freeSpace ${file.freeSpace}")
    println("file.isFile ${file.isFile}")
    println("file.name ${file.name}")
    println("file.parent ${file.parent}")
    println("file.path ${file.path}")

    if (file.delete()) {
        println("删除 $filename 成功")
    }

}